/**
 * @param {number[]} A
 * @param {number[]} B
 * @param {number[]} C
 * @param {number[]} D
 * @return {number}
 */

type NumberArray = number[]

var fourSumCount = function (A: NumberArray, B: NumberArray, C: NumberArray, D: NumberArray) {

    const mapAB = new Map<number, number>()
    const mapCD = new Map<number, number>()

    for (const a of A) {
        for (const b of B) {
            const key = a + b
            const c = mapAB.get(key) || 0
            mapAB.set(key, c + 1)
        }
    }


    for (const c of C) {
        for (const d of D) {
            const key = -c - d
            const x = mapCD.get(key) || 0
            mapCD.set(key, x + 1)
        }
    }

    let ans = 0;

    for (const [k, c1] of  mapAB) {
        const c2 = mapCD.get(k)
        if (c2) {
            ans += c1 * c2
        }
    }

    console.log(mapAB, mapCD)
    console.log(ans)
    return ans
};

fourSumCount(
    [1, 2],
    [-2, -1],
    [-1, 2],
    [0, 2]
)